/* 
 * Copyright (C)2008 Vladimir Hozjan vladimir.hozjan@gmail.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */

/**
 * @file  tetrisFunctor.h
 *
 * Functor callback mechanism for tetris engine
 *
 * @author Vladimir Hozjan
 * @date   25.12.2008 
 *
 * @remarks VHOZ [25.12.2008]: File created
 */
#ifndef _tetrisFunctor_h_
#define _tetrisFunctor_h_

/**
 * @class ITetrisFunctor
 * @brief Interface for tetris functor
 *
 * Abstract interface for tetris functor. This class is used for callback call.
 *
 * @author VHOZ
 *
 * @remarks VHOZ [25.12.2008]: Class created
 */
class ITetrisFunctor {
public:
  /// Constructor
  ITetrisFunctor(){};

  /// Destructor
  virtual ~ITetrisFunctor(){};

  /// Create duplicate of this class
  virtual ITetrisFunctor *duplicate() = 0;

  /// callback method
  virtual void operator()() = 0;
protected:
private:
};

/**
 * @class TTetrisFunctor
 * @brief Template class for callback.
 *
 * Template class that contains class instance and reference to
 * method. It is also used to call callback method
 *
 * @author VHOZ
 *
 * @remarks VHOZ [25.12.2008]: Class created
 */
template <class T>
class TTetrisFunctor : public ITetrisFunctor{
public:
  /// Constructor
  TTetrisFunctor(T * aClass, void (T::*aMethod)()) : mClass(aClass), mMethod(aMethod) {};

  /// Destructor
  virtual ~TTetrisFunctor(){};

  /// Create duplicate of this class
  virtual ITetrisFunctor *duplicate(){
    return new TTetrisFunctor<T>(*this) ;
  };

  /// callback method
  virtual void operator()() {
    (mClass->*(mMethod))();
  };

protected:
private:
  /// Constructor
  TTetrisFunctor();

  T *mClass;
  void (T::*mMethod)();
};
#endif // _tetrisFunctor_h_
